<template>
  <div class="dashboard-container">
    <!-- Top Navigation -->
    <header class="top-nav">
      <div class="nav-header">
        <img src="https://web-sui.oss-cn-hangzhou.aliyuncs.com/ef840c64-a2b7-4965-865d-db1f24c3c269.png" alt="Logo" class="nav-logo">
        <h2>慧医数字医疗</h2>
      </div>
      <div class="nav-menu-wrapper">
        <span class="scroll-indicator left" @click="scrollLeft" v-if="maxScrollOffset > 0 && scrollOffset > 0">
          <span>&lt;</span>
        </span>
        <nav class="nav-menu" @wheel="handleNavScroll" ref="navMenu">
          <ul class="nav-list" ref="navList">
            <li class="nav-item" :class="{ active: currentMenu === 'home' }">
              <a href="#" @click.prevent="selectMenu('home')">
                <span class="nav-icon"></span>
                首页
              </a>
            </li>
            <!-- 只有管理员能看到医师管理 -->
            <li v-if="props.userRole === 'admin'" class="nav-item" :class="{ active: currentMenu === 'doctor' }">
              <a href="#" @click.prevent="selectMenu('doctor')">
                <span class="nav-icon"></span>
                医师管理
              </a>
            </li>
            <li class="nav-item" :class="{ active: currentMenu === 'company' }">
              <a href="#" @click.prevent="selectMenu('company')">
                <span class="nav-icon"></span>
                公司管理
              </a>
            </li>
            <li class="nav-item" :class="{ active: currentMenu === 'material' }">
              <a href="#" @click.prevent="selectMenu('material')">
                <span class="nav-icon"></span>
                材料管理
              </a>
            </li>
            <li class="nav-item" :class="{ active: currentMenu === 'location' }">
              <a href="#" @click.prevent="selectMenu('location')">
                <span class="nav-icon"></span>
                药店管理
              </a>
            </li>
            <li class="nav-item" :class="{ active: currentMenu === 'medicine' }">
              <a href="#" @click.prevent="selectMenu('medicine')">
                <span class="nav-icon"></span>
                药品管理
              </a>
            </li>
            <!-- 只有管理员能看到的功能 -->
            <template v-if="props.userRole === 'admin'">
            <li class="nav-item" :class="{ active: currentMenu === 'policy' }">
              <a href="#" @click.prevent="selectMenu('policy')">
                <span class="nav-icon"></span>
                政策管理
              </a>
            </li>
            <li v-if="props.userRole === 'admin'" class="nav-item detail-nav" :class="{ active: currentMenu === 'detail' }">
              <a href="#" @click.prevent="toggleDetailSubmenu">
                类别管理
              </a>
            <ul v-if="showDetailSubmenu" class="submenu">
                <li :class="{ active: currentSubMenu === 'doctor' }">
                  <a href="#" @click.prevent="selectSubMenu('doctor')">
                    <span class="submenu-icon"></span>
                    医师
                  </a>
                </li>
                <li :class="{ active: currentSubMenu === 'company' }">
                  <a href="#" @click.prevent="selectSubMenu('company')">
                    <span class="submenu-icon"></span>
                    公司
                  </a>
                </li>
                <li :class="{ active: currentSubMenu === 'medicine' }">
                  <a href="#" @click.prevent="selectSubMenu('medicine')">
                    <span class="submenu-icon"></span>
                    药品
                  </a>
                </li>
            </ul>
          </li>
            </template>
          </ul>
        </nav>
        <span class="scroll-indicator right" @click="scrollRight" v-if="maxScrollOffset > 0 && scrollOffset < maxScrollOffset">
          <span>&gt;</span>
        </span>
      </div>
      <div class="nav-user">
        <span class="welcome-text">欢迎您，{{ props.userName }}</span>
        <div class="settings-dropdown">
          <button class="settings-button" @click="toggleSettingsMenu">
            <span class="settings-icon">⚙️</span>
            设置
          </button>
          <div v-if="showSettingsMenu" class="settings-menu">
            <button class="settings-item" @click="openChangePasswordModal">
              <span class="item-icon">🔒</span>
              修改密码
            </button>
            <button class="settings-item" @click="$emit('logout')">
              <span class="item-icon">🚪</span>
              退出登录
            </button>
          </div>
        </div>
      </div>
    </header>

    <!-- Main Content -->
    <div class="main-content">
      <div class="content-header">
        <div class="breadcrumb">
          <span class="breadcrumb-item">首页</span>
          <span v-if="currentMenu !== 'home'" class="breadcrumb-separator">/</span>
          <span v-if="currentMenu !== 'home'" class="breadcrumb-item">{{ getMenuTitle(currentMenu) }}</span>
        </div>
        </div>
      <main class="content-area">
        <component 
          :is="currentComponent" 
          :account="account" 
          :userRole="props.userRole"
          :stats="stats" 
          :currentSubMenu="currentSubMenu" 
          @update:currentSubMenu="updateCurrentSubMenu"
          @logout="$emit('logout')"
        />
      </main>
    </div>
  </div>

  <!-- 修改密码弹窗 -->
  <div v-if="showChangePasswordModal" class="modal-overlay" @click="showChangePasswordModal = false">
    <div class="modal-content" @click.stop>
      <div class="modal-header">
        <h3>修改密码</h3>
        <button @click="showChangePasswordModal = false" class="close-btn">&times;</button>
      </div>
      <div class="modal-body">
        <div class="form-group">
          <label>当前密码：</label>
          <input v-model="changePasswordForm.oldPassword" type="password" placeholder="请输入当前密码" class="password-input" />
        </div>
        <div class="form-group">
          <label>新密码：</label>
          <input v-model="changePasswordForm.newPassword" type="password" placeholder="请输入新密码" class="password-input" @input="passwordError = ''" />
          <div v-if="passwordError" class="error-msg">{{ passwordError }}</div>
        </div>
        <div class="form-group">
          <label>确认新密码：</label>
          <input v-model="changePasswordForm.confirmPassword" type="password" placeholder="请再次输入新密码" class="password-input" @input="passwordError = ''" />
        </div>
      </div>
      <div class="modal-footer">
        <button @click="changePassword" class="confirm-btn">确认修改</button>
        <button @click="cancelChangePassword" class="cancel-btn">取消</button>
      </div>
      <div v-if="message" :class="['error-msg', messageType === 'success' ? 'success-msg' : '']" style="text-align:center;">{{ message }}</div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, computed, nextTick } from 'vue';
import axios from 'axios';
import DoctorManagement from './DoctorManagement.vue';
import HomeDashboard from './HomeDashboard.vue';
import CompanyManagement from './CompanyManagement.vue';
import MaterialManagement from './MaterialManagement.vue';
import LocationManagement from './LocationManagement.vue';
import MedicineManagement from './MedicineManagement.vue';
import DetailManagement from './DetailManagement.vue';
import PolicyManagement from './PolicyManagement.vue';

const props = defineProps({
  account: {
    type: String,
    required: true
  },
  currentPassword: {
    type: String,
    required: true
  },
  userRole: {
    type: String,
    required: true
  },
  userName: {
    type: String,
    required: true
  }
});

const emit = defineEmits(['logout', 'password-change']);

const stats = ref({
  doctors: 0,
  medicines: 0,
  companies: 0,
  locations: 0,
});

const currentMenu = ref('home');
const currentSubMenu = ref('doctor');
const showDetailSubmenu = ref(false);
const navMenu = ref(null);
const navList = ref(null);
const scrollOffset = ref(0);
const maxScrollOffset = ref(0);
const showSettingsMenu = ref(false);
const showChangePasswordModal = ref(false);
const passwordError = ref('');
const message = ref('');
const messageType = ref('');

// 修改密码表单数据
const changePasswordForm = ref({
  oldPassword: '',
  newPassword: '',
  confirmPassword: ''
});

const currentComponent = computed(() => {
  // 普通用户不能访问 doctor 页面
  if (currentMenu.value === 'doctor' && props.userRole !== 'admin') {
    return HomeDashboard;
  }
  switch (currentMenu.value) {
    case 'home':
      return HomeDashboard;
    case 'doctor':
      return DoctorManagement;
    case 'company':
      return CompanyManagement;
    case 'material':
      return MaterialManagement;
    case 'location':
      return LocationManagement;
    case 'medicine':
      return MedicineManagement;
    case 'policy':
      return PolicyManagement;
    case 'detail':
      return DetailManagement;
    case 'profile':
      return { template: `<div class="user-profile">个人信息页面</div>` };
    case 'records':
      return { template: `<div class="user-records">我的记录页面</div>` };
    default:
      return { template: `<div>欢迎使用系统！</div>` };
  }
});

function selectMenu(menu) {
  // 普通用户不能切 doctor 页面
  if (menu === 'doctor' && props.userRole !== 'admin') {
    return;
  }
  currentMenu.value = menu;
  // 细节管理默认医师，政策管理默认医药公司政策
  if (menu === 'detail') {
    currentSubMenu.value = 'doctor';
  } else if (menu === 'policy') {
    currentSubMenu.value = 'company-policy';
  }
}

function toggleDetailSubmenu() {
  showDetailSubmenu.value = !showDetailSubmenu.value;
  if (showDetailSubmenu.value) {
    selectMenu('detail');
  }
}

function selectSubMenu(subMenu) {
  currentSubMenu.value = subMenu;
}

function getMenuTitle(menu) {
  const menuTitles = {
    'home': '首页',
    'doctor': '医师管理',
    'company': '医药公司管理',
    'material': '必备材料管理',
    'location': '药店管理',
    'medicine': '药品信息管理',
    'policy': '政策管理',
    'detail': '类别管理'
  };
  return menuTitles[menu] || '未知页面';
}

function handleNavScroll(event) {
  event.preventDefault();
  
  const scrollAmount = event.deltaY > 0 ? 1 : -1;
  const newOffset = scrollOffset.value + scrollAmount;
  
  // 限制滚动范围
  if (newOffset >= 0 && newOffset <= maxScrollOffset.value) {
    scrollOffset.value = newOffset;
    updateNavScroll();
  }
}

function updateNavScroll() {
  if (navList.value) {
    const translateX = -scrollOffset.value * 20; // 每个导航项占20%宽度
    navList.value.style.transform = `translateX(${translateX}%)`;
  }
}

function calculateMaxScroll() {
  if (navList.value) {
    const totalItems = navList.value.children.length;
    maxScrollOffset.value = Math.max(0, totalItems - 5);
  }
}

function scrollLeft() {
  scrollOffset.value = Math.max(0, scrollOffset.value - 1);
  updateNavScroll();
}

function scrollRight() {
  scrollOffset.value = Math.min(maxScrollOffset.value, scrollOffset.value + 1);
  updateNavScroll();
}

function updateCurrentSubMenu(subMenu) {
  currentSubMenu.value = subMenu;
}

function toggleSettingsMenu() {
  showSettingsMenu.value = !showSettingsMenu.value;
}

// 点击外部关闭设置菜单
function closeSettingsMenu() {
  showSettingsMenu.value = false;
}

function showMessage(msg, type = 'success') {
  message.value = msg;
  messageType.value = type;
  setTimeout(() => {
    message.value = '';
    messageType.value = '';
  }, 3000);
}

// 修改密码功能
async function changePassword() {
  const { oldPassword, newPassword, confirmPassword } = changePasswordForm.value;
  
  // 验证表单
  if (!oldPassword || !newPassword || !confirmPassword) {
    passwordError.value = '请填写完整的密码信息';
    return;
  }
  
  const pwdPattern = /^[A-Za-z0-9]{6,20}$/;
  if (!pwdPattern.test(newPassword)) {
    passwordError.value = '新密码只能为6-20位字母或数字';
    return;
  }
  
  if (newPassword !== confirmPassword) {
    passwordError.value = '新密码与确认密码不一致';
    return;
  }
  
  try {
    // 获取token
    const token = localStorage.getItem('token');
    if (!token) {
      alert('登录已过期，请重新登录');
      emit('logout');
      return;
    }
    
    // 调用后端API
    const response = await axios.post('http://47.93.134.56:8800/user/changePassword', {
      oldPassword: oldPassword,
      newPassword: newPassword
    }, {
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      }
    });
    
    // 检查响应
    if (response.data.code === 200) {
      showMessage(response.data.msg || '密码修改成功');
      emit('password-change', newPassword); // 通知父组件密码已修改
      cancelChangePassword(); // 修改成功后自动关闭弹窗
    } else {
      showMessage(`密码修改失败：${response.data.msg || '未知错误'}`);
    }
  } catch (error) {
    console.error('修改密码错误:', error);
    if (error.response) {
      if (error.response.status === 401) {
        alert('登录已过期，请重新登录');
        emit('logout');
      } else {
        alert(`密码修改失败：${error.response.data?.msg || '服务器错误'}`);
      }
    } else {
      alert('网络错误，请检查网络连接');
    }
  }
}

function cancelChangePassword() {
  changePasswordForm.value = {
    oldPassword: '',
    newPassword: '',
    confirmPassword: ''
  };
  showChangePasswordModal.value = false;
}

function openChangePasswordModal() {
  changePasswordForm.value = {
    oldPassword: '',
    newPassword: '',
    confirmPassword: ''
  };
  passwordError.value = '';
  showChangePasswordModal.value = true;
}

onMounted(() => {
  stats.value = {
    doctors: Math.floor(Math.random() * 500) + 100,
    medicines: Math.floor(Math.random() * 2000) + 500,
    companies: Math.floor(Math.random() * 100) + 20,
    locations: Math.floor(Math.random() * 800) + 150,
  };
  
  // 计算最大滚动偏移量
  nextTick(() => {
    calculateMaxScroll();
  });
  
  // 添加全局点击事件监听
  document.addEventListener('click', (event) => {
    const settingsDropdown = document.querySelector('.settings-dropdown');
    if (settingsDropdown && !settingsDropdown.contains(event.target)) {
      closeSettingsMenu();
    }
  });
  
  // 监听切换到政策管理页面的事件
  window.addEventListener('switchToPolicy', () => {
    selectMenu('policy');
  });
});
</script>

<style scoped>
.dashboard-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

/* Top Navigation */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  color: white;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  z-index: 1000;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  box-sizing: border-box;
  height: 80px;
}

.nav-header {
  display: flex;
  align-items: center;
}

.nav-logo {
  width: 55px;
  height: 52px;
  margin-right: 15px;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.nav-header h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.nav-menu-wrapper {
  display: flex;
  align-items: center;
  flex-grow: 1;
  justify-content: center;
  position: relative;
  width: 100%;
  max-width: 600px;
}

.nav-menu {
  display: flex;
  align-items: center;
  flex-grow: 1;
  justify-content: center;
  overflow: hidden;
  position: relative;
  width: 100%;
  max-width: 600px;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 0;
  width: 500%;
  transition: transform 0.3s ease;
  transform: translateX(0);
}

.nav-item {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  flex: 0 0 20%;
  min-width: 20%;
  max-width: 20%;
  flex-shrink: 0;
}

.nav-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transition: left 0.5s ease;
}

.nav-item:hover::before {
  left: 100%;
}

.nav-item a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 8px;
  color: #bdc3c7;
  text-decoration: none;
  transition: all 0.3s ease;
  border-radius: 12px;
  position: relative;
  z-index: 1;
  font-weight: 500;
  letter-spacing: 0.5px;
  white-space: nowrap;
  text-align: center;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  font-size: 0.85rem;
}

.nav-icon {
  font-size: 1.2rem;
  transition: all 0.3s ease;
  filter: grayscale(0.5);
  margin-bottom: 2px;
}

.nav-item a:hover .nav-icon,
.nav-item.active a .nav-icon {
  filter: grayscale(0);
  transform: scale(1.1);
}

.nav-item a:hover {
  color: white;
  transform: translateY(-2px);
}

.nav-item.active a {
  color: white;
  font-weight: 600;
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* 不同导航项的颜色 */
.nav-item:nth-child(1) a:hover,
.nav-item:nth-child(1).active a {
  background: rgba(255, 255, 255, 0.1);
}

.nav-item:nth-child(2) a:hover,
.nav-item:nth-child(2).active a {
  background: rgba(255, 255, 255, 0.1);
}

.nav-item:nth-child(3) a:hover,
.nav-item:nth-child(3).active a {
  background: rgba(255, 255, 255, 0.1);
}

.nav-item:nth-child(4) a:hover,
.nav-item:nth-child(4).active a {
  background: rgba(255, 255, 255, 0.1);
}

.nav-item:nth-child(5) a:hover,
.nav-item:nth-child(5).active a {
  background: rgba(255, 255, 255, 0.1);
}

.nav-item:nth-child(6) a:hover,
.nav-item:nth-child(6).active a {
  background: rgba(255, 255, 255, 0.1);
}

.nav-item:nth-child(7) a:hover,
.nav-item:nth-child(7).active a {
  background: rgba(255, 255, 255, 0.1);
  
}
.nav-item:nth-child(8) a:hover,
.nav-item:nth-child(8).active a {
  background: rgba(255, 255, 255, 0.1);
}

/* 二级菜单样式 */
.detail-nav {
  position: relative;
}

.submenu {
  list-style: none;
  padding: 0;
  margin: 0;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 8px;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 120px;
  overflow: hidden;
  animation: slideDown 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes slideUp {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
}

.submenu li {
  padding: 0;
  margin: 0;
}

.submenu li a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 15px;
  color: #bdc3c7;
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  border-radius: 0;
  margin: 0;
  white-space: nowrap;
}

.submenu-icon {
  font-size: 0.9rem;
  transition: all 0.3s ease;
  filter: grayscale(0.5);
}

.submenu li a:hover .submenu-icon,
.submenu li.active a .submenu-icon {
  filter: grayscale(0);
  transform: scale(1.1);
}

.submenu li a:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  transform: translateX(3px);
}

.submenu li.active a {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-weight: 600;
  transform: translateX(3px);
  box-shadow: 0 2px 10px rgba(102, 126, 234, 0.4);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 20px;
}

.welcome-text {
  font-size: 0.9rem;
  color: #bdc3c7;
  font-weight: 500;
}

.settings-dropdown {
  position: relative;
}

.settings-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
  position: relative;
  overflow: hidden;
}

.settings-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.settings-button:hover::before {
  left: 100%;
}

.settings-button:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.settings-icon {
  font-size: 1rem;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.settings-menu {
  list-style: none;
  padding: 0;
  margin: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 140px;
  width: auto;
  overflow: hidden;
  animation: slideDown 0.3s ease;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  margin-top: 8px;
}

.settings-menu::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 20px;
  width: 12px;
  height: 12px;
  background: rgba(255, 255, 255, 0.95);
  transform: rotate(45deg);
  border-left: 1px solid rgba(255, 255, 255, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.settings-item {
  padding: 12px 18px;
  color: #333;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.3s ease;
  border-radius: 0;
  margin: 0;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  position: relative;
  overflow: hidden;
  width: 100%;
  box-sizing: border-box;
}

.settings-item:last-child {
  border: none;
}

.settings-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  transition: width 0.3s ease;
  z-index: -1;
}

.settings-item:hover {
  background: transparent;
  color: white;
  transform: translateX(5px);
}

.settings-item:hover::before {
  width: 100%;
}

.item-icon {
  font-size: 1rem;
  transition: all 0.3s ease;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
  z-index: 1;
}

.settings-item:hover .item-icon {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
  transform: scale(1.1);
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-top: 80px;
  height: calc(100vh - 80px);
  min-width: 0;
  background: #fcfcfc;
  position: relative;
}

.content-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 20px 30px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
  z-index: 50;
  position: relative;
}

.content-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.1), transparent);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #666;
}

.breadcrumb-item {
  font-weight: 500;
  color: #333;
}

.breadcrumb-separator {
  color: #ccc;
}

.content-area {
  flex-grow: 1;
  padding: 10px;
  overflow-y: auto;
  background: transparent;
  height: calc(100vh - 160px);
  min-height: 0;
  position: relative;
  display: block;
}

.content-area::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.05), transparent);
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .top-nav {
    padding: 12px 20px;
  }
  
  .nav-menu {
    max-width: 500px;
  }
  
  .nav-item a {
    padding: 10px 6px;
    font-size: 0.8rem;
  }
  
  .nav-icon {
    font-size: 1.1rem;
  }
  
  .content-area {
    padding: 20px;
  }
}

@media (max-width: 768px) {
  .dashboard-container {
    flex-direction: column;
  }
  
  .top-nav {
    flex-direction: column;
    gap: 15px;
    padding: 15px;
    height: auto;
  }
  
  .nav-menu {
    width: 100%;
    max-width: none;
    overflow-x: auto;
  }
  
  .nav-list {
    gap: 5px;
    min-width: max-content;
    width: auto;
    transform: none !important;
  }
  
  .nav-item {
    max-width: none;
    flex: none;
    min-width: 120px;
    flex: 0 0 auto;
  }
  
  .nav-item a {
    padding: 8px 12px;
    font-size: 0.85rem;
    flex-direction: row;
    gap: 8px;
  }
  
  .nav-icon {
    margin-bottom: 0;
  }
  
  .scroll-indicator {
    display: none;
  }
  
  .nav-user {
    gap: 10px;
  }
  
  .welcome-text {
    display: none;
  }
  
  .main-content {
    height: auto;
    flex-grow: 1;
    margin-top: 0;
  }
  
  .content-area {
    height: auto;
    min-height: calc(40vh - 80px);
  }
  
  .content-header {
    padding: 15px 20px;
  }
}

@media (max-width: 480px) {
  .nav-header h2 {
    font-size: 1.1rem;
  }
  
  .nav-logo {
    width: 40px;
    height: 40px;
  }
  
  .nav-item a {
    padding: 6px 10px;
    font-size: 0.8rem;
  }
  
  .content-area {
    padding: 15px;
  }
  
  .content-header {
    padding: 10px 15px;
  }
  
  .settings-button {
    padding: 8px 14px;
    font-size: 0.8rem;
  }
  
  .settings-menu {
    min-width: 140px;
  }
  
  .settings-item {
    padding: 12px 18px;
    font-size: 0.8rem;
  }
  
  .modal-content {
    width: 95%;
    margin: 10px;
  }
  
  .modal-header {
    padding: 15px;
  }
  
  .modal-body {
    padding: 15px;
  }
  
  .modal-footer {
    padding: 15px;
  }
}

/* 滚动条样式 */
.content-area::-webkit-scrollbar {
  width: 8px;
}

.content-area::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.content-area::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.content-area::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* Scroll Indicator Styles */
.scroll-indicator {
  position: relative;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  transition: all 0.3s ease;
  opacity: 0.7;
  margin: 0 6px;
  font-size: 1.2rem;
  color: #fff;
  user-select: none;
}

.scroll-indicator:hover {
  background: rgba(0, 0, 0, 0.7);
  opacity: 1;
  transform: scale(1.1);
}

.scroll-indicator.left {
  left: 0;
}

.scroll-indicator.right {
  right: 0;
}

/* 弹窗样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background: white;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 {
  margin: 0;
  color: #333;
  font-size: 1.2rem;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: #f0f0f0;
  color: #333;
}

.modal-body {
  padding: 20px;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  color: #333;
  font-weight: 500;
}

.password-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.9rem;
  box-sizing: border-box;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 20px;
  border-top: 1px solid #e0e0e0;
}

.confirm-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
  position: relative;
  overflow: hidden;
}

.confirm-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.confirm-btn:hover::before {
  left: 100%;
}

.confirm-btn:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.cancel-btn {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
  position: relative;
  overflow: hidden;
}

.cancel-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.cancel-btn:hover::before {
  left: 100%;
}

.cancel-btn:hover {
  background: linear-gradient(135deg, #5a6268 0%, #343a40 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(108, 117, 125, 0.4);
}

.error-msg {
  color: #ff1b02;
  font-size: 0.95rem;
  margin-bottom: 8px;
  margin-left: 2px;
}

.success-msg {
  color: #e54646;
}
</style>